package team18.yuejian.Model;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import team18.yuejian.RetrofitListener;
import team18.yuejian.Server.CommonServer;
import team18.yuejian.bean.LoginBean;
import team18.yuejian.bean.NoteBean;
import team18.yuejian.bean.RegBean;
import team18.yuejian.bean.UserBean;

public class CommonModel extends RetrofitModel{
    private String url;

    private Retrofit retrofit;

    private RetrofitModel retrofitModel;

    public CommonModel(){
        retrofitModel = new RetrofitModel();
        url = retrofitModel.getBaseUrl();
        retrofit = new Retrofit.Builder()
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void UserLogin(String uname, String upassword, final RetrofitListener listener){
        CommonServer server = retrofit.create(CommonServer.class);
        Call<LoginBean> call = server.Login(uname,upassword);
        bindCallback(call,listener,null,0);

    }

    public void UserReg(String name,String phone,String password,int gender,final RetrofitListener listener){
        CommonServer server = retrofit.create(CommonServer.class);
        Call<RegBean> call = server.Reg(name,phone,password,gender);
        bindCallback(call,listener,null,1);
    }

    public void UserRePassword(String name,String phone,String newPassword,final RetrofitListener listener){
        CommonServer commonServer = retrofit.create(CommonServer.class);
        Call<NoteBean> call = commonServer.RePassword(name,phone,newPassword);
        bindCallback(call,listener,null,2);
    }
}
